import type { Page } from '@/types/common'
import type { Role, RoleData, RoleDetail, RoleItemParams, RoleUserData } from '@/types/system'
import { myRequest } from '@/utils/reuqest'

/**
 * 获取角色列表
 * @returns
 */
export const getRoleListAPI = () => {
  return myRequest<Role[]>('/park/sys/role', 'GET')
}

/**
 * 获取tree权限列表
 * @returns
 */
export const getTreeListAPI = ()=>{
    return myRequest<RoleData[]>('/park/sys/permision/all/tree', 'GET');
}

/**
 * 查询当前角色详情-权限和分配人数
 * @returns
 */
export const getRoleDetailAPI = (roleId: number) =>{
  return myRequest<RoleDetail>(`/park/sys/role/${roleId}`, 'GET')
}

/**
 * 获取角色成员列表
 * @returns
 */
export const getRoleUserAPI = (roleId: number, params: Page) => {
  return myRequest<RoleUserData>(`/park/sys/roleUser/${roleId}`, 'GET', params)
}

// 添加成员列表
export const addUserApi = (params: RoleItemParams) => {
  return myRequest('/park/sys/role', 'POST', params)
}

// 删除成员
export const delUserApi = (id: number) => {
  return myRequest(`/park/sys/role/${id}`, 'DELETE')
}

// 编辑成员
export const editUserAPI = (params: RoleItemParams, id: number) => {
  return myRequest('/park/sys/role', 'PUT', { ...params, roleId: id })
}